package com.example.zhangxin.comevedio.activity.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by ZhangXin on 2016/9/14.
 */

public class HomeViewPager extends ViewPager {

    private int down;
    private int up;

    public HomeViewPager(Context context) {
        super(context);
    }

    public HomeViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if(getCurrentItem()!=0){
            getParent().requestDisallowInterceptTouchEvent(true);
        }else{
            int action = ev.getAction();
            if(action==MotionEvent.ACTION_DOWN){
                down = (int) ev.getX();
            }
            if(action==MotionEvent.ACTION_MOVE){
                up = (int) ev.getX();
            }
            if(down>up){
                getParent().requestDisallowInterceptTouchEvent(true);
            }else{
                getParent().requestDisallowInterceptTouchEvent(false);

            }
        }
        return super.dispatchTouchEvent(ev);
    }
}
